<?php

namespace app\modules\backend\controllers;


use app\models\Base;
use app\models\UserLogin;
use app\tools\Re;

class UserLoginController extends BaseController
{
    protected $fields = ['id', 'create_nickname', 'ip', 'time'];

    public function actionIndex($user_id, $page = 0){
        $query = UserLogin::find()
            ->where(['user_id'=>$user_id]);

        $list = $query->orderBy('id desc')
            ->limit(UserLogin::PAGE_SIZE)
            ->offset(UserLogin::PAGE_SIZE * $page)
            ->all();
        return Re::data([
            'data'        => Base::buildParamsList($list, $this->fields),
            'totalPage'   => $query->count(),
            'currentPage' => $page,
            'perPage'     => UserLogin::PAGE_SIZE
        ]);
    }
}
